import M from '../../../../common/typeMutations'
import A from '../../../../common/typeActions'
import L from '../../../../common/localStore'
import { action } from '../../../../common/quantity'

const state = {
  // 最近打开文件列表
  recentFiles: [],
  // 用户信息
  userInfo: {}
}

const mutations = {
  // 初始化主界面
  [M.MAINPAGE.INIT_MAINPAGE] (state, payload) {
    state.recentFiles = payload
  },
  [M.MAINPAGE.SET_USERINFO] (state, payload) {
    for (let key in payload) {
      state.userInfo[key] = payload[key]
    }
  },
  // 获取最近打开文件列表
  [M.MAINPAGE.GET_RECENT_FILES] (state, payload) {
    state.recentFiles = payload
  }

}

const actions = {
  /**
   * 初始化主界面
   */
  [A.MAINPAGE.initMainPage] (ctx, data) {
    ctx.commit(M.MAINPAGE.INIT_MAINPAGE, L.LocalStore.getRecentFiles())
  },

  /**
   * 修改最近打开文件列表
   */
  [action.mainPage.setRecentFiles] (ctx, data) {
    L.LocalStore.setRecentFiles(data)
    ctx.commit(M.MAINPAGE.GET_RECENT_FILES, L.LocalStore.getRecentFiles())
  }

}

const getters = {
  // getUnitObj(state) {
  //   console.log(state.userInfo)
  //   return {
  //     DWMC: state.userInfo.unitCode ? state.userInfo.unitName : '',
  //     DWBM: state.userInfo.unitCode
  //   };
  // }
}

export default {
  state,
  mutations,
  actions,
  getters
}
